package com.tencent.mid.b;

import android.content.Context;
import com.tencent.mid.api.MidEntity;
import com.tencent.mid.util.Util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class g
{
  private static g b = null;
  private Map a = null;
  private MidEntity c = null;

  private g(Context paramContext)
  {
    this.a.put(Integer.valueOf(1), new e(paramContext));
    this.a.put(Integer.valueOf(2), new c(paramContext));
    this.a.put(Integer.valueOf(4), new d(paramContext));
  }

  public static g a(Context paramContext)
  {
    monitorenter;
    try
    {
      if (b == null)
        b = new g(paramContext);
      paramContext = b;
      return paramContext;
    }
    finally
    {
      monitorexit;
    }
  }

  public MidEntity a()
  {
    if ((this.c == null) || (!(this.c.isMidValid())))
      this.c = a(new ArrayList(Arrays.asList(new Integer[] { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(4) })));
    return this.c;
  }

  public MidEntity a(List paramList)
  {
    Object localObject;
    if ((paramList == null) || (paramList.size() == 0))
      return null;
    paramList = paramList.iterator();
    while (paramList.hasNext())
    {
      localObject = (Integer)paramList.next();
      localObject = (f)this.a.get(localObject);
      if (localObject == null)
        continue;
      localObject = ((f)localObject).i();
      if ((localObject != null) && (((MidEntity)localObject).isMidValid()))
        return localObject;
    }
    return ((MidEntity)null);
  }

  public void a(int paramInt1, int paramInt2)
  {
    a locala = b();
    if (paramInt1 > 0)
      locala.c(paramInt1);
    if (paramInt2 > 0)
      locala.a(paramInt2);
    locala.a(System.currentTimeMillis());
    locala.b(0);
    a(locala);
  }

  public void a(MidEntity paramMidEntity)
  {
    if ((!(paramMidEntity.isForceWrite())) && (this.c != null) && (Util.isMidValid(this.c.getMid())))
      return;
    Iterator localIterator = this.a.entrySet().iterator();
    while (localIterator.hasNext())
      ((f)((Map.Entry)localIterator.next()).getValue()).a(paramMidEntity);
  }

  public void a(a parama)
  {
    Iterator localIterator = this.a.entrySet().iterator();
    while (localIterator.hasNext())
      ((f)((Map.Entry)localIterator.next()).getValue()).b(parama);
  }

  public a b()
  {
    return b(new ArrayList(Arrays.asList(new Integer[] { Integer.valueOf(1), Integer.valueOf(4) })));
  }

  public a b(List paramList)
  {
    Object localObject;
    if ((paramList == null) || (paramList.size() == 0))
      return null;
    paramList = paramList.iterator();
    while (paramList.hasNext())
    {
      localObject = (Integer)paramList.next();
      localObject = (f)this.a.get(localObject);
      if (localObject == null)
        continue;
      localObject = ((f)localObject).k();
      if (localObject != null)
        return localObject;
    }
    return ((a)null);
  }

  public void c()
  {
    Util.logInfo("clear mid cache");
    Iterator localIterator = this.a.entrySet().iterator();
    while (localIterator.hasNext())
      ((f)((Map.Entry)localIterator.next()).getValue()).j();
  }
}